<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>014父子组件之间数据传递</title>
  <script src="./vue.js"></script>
</head>
<body>
  <div id="root">
    <div>这是父组件，第一个孩子是{{number}}--{{childContent}}</div>
    <childone @trans="receive"></childone>
  </div>
  <script>
    var vm = new Vue({
      el: "#root",
      data: {
        numberFather: 0,
        fatherData: "父组件"
      },
      components: {
        "childone": {
            props:["number", "fatherData"],
            template: "<div @click='handleClick'>{{content}}---{{number}}</div>",
            data: function() {
              return {
                content: "childOne",
                number: 11,
                childContent: ""
              }
            },
            methods: {
              handleClick: function() {
                this.$emit("trans", this.number, this.content);
              }
            },
        }
      },
      methods: {
        receive: function(number, childContent) {
          console.log(number);
          this.number = number;
          this.childContent = childContent;
          console.log(this.numberFather, this.fatherData, "hello");
        }
      }
    })
  </script>
</body>
</html>